<?php

namespace app\models\Child;

use Yii;

/**
 * This is the model class for table "t_subclinic_info".
 *
 * @property integer $subclinic_id
 * @property string $subclinic_name
 * @property string $subclinic_logo
 * @property string $subclinic_phone
 * @property string $subclinic_start_time
 * @property string $subclinic_end_time
 * @property string $subclinic_address
 * @property string $subclinic_lat_lon
 * @property string $subclinic_desc
 * @property integer $subclinic_status
 * @property string $create_time
 *
 * @property SysUserInfo[] $sysUserInfos
 * @property TBookingInfo[] $tBookingInfos
 */
class TSubclinicInfo extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_subclinic_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['subclinic_status'], 'integer'],
            [['create_time'], 'safe'],
            [['subclinic_name', 'subclinic_logo', 'subclinic_address', 'subclinic_lat_lon', 'subclinic_desc'], 'string', 'max' => 100],
            [['subclinic_phone'], 'string', 'max' => 11],
            [['subclinic_start_time', 'subclinic_end_time'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'subclinic_id' => 'Subclinic ID',
            'subclinic_name' => 'Subclinic Name',
            'subclinic_logo' => 'Subclinic Logo',
            'subclinic_phone' => 'Subclinic Phone',
            'subclinic_start_time' => 'Subclinic Start Time',
            'subclinic_end_time' => 'Subclinic End Time',
            'subclinic_address' => 'Subclinic Address',
            'subclinic_lat_lon' => 'Subclinic Lat Lon',
            'subclinic_desc' => 'Subclinic Desc',
            'subclinic_status' => 'Subclinic Status',
            'create_time' => 'Create Time',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSysUserInfos()
    {
        return $this->hasMany(SysUserInfo::className(), ['subclinic_id' => 'subclinic_id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSubclinicInfo($subclinic_id)
    {
        $list = $this->find()
            ->where(['subclinic_id' => $subclinic_id])
            ->asArray()
            ->one();
        return $list;
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTBookingInfos()
    {
        return $this->hasMany(TBookingInfo::className(), ['subclinic_id' => 'subclinic_id']);
    }
    /*
     * 获取分店列表
     */
    public function getSubclinicList($subclinic_id)
    {
        if(!empty($subclinic_id))
        {
            $list = $this->find()
                    ->where(['subclinic_id' => $subclinic_id])
                    ->asArray()
                    ->one();
        }else{
            $list = $this->find()
                    ->asArray()
                    ->all();
        }
        
        return $list;
    }
}
